//
//  PEVppCommonModel.m
//  PrivateApp
//
//  Created by Yan Chen on 2025/6/30.
//

#import "RHVppSetCommonModel.h"

@implementation RHVppSetCommonModel
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper
{
    return @{@"num":@"bitWidth"};
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{@"rows" : [RHVppSetCommonModel class],
             @"items" : [RHVppSetCommonModel class],
             @"selectList":[DevSettingOptionModel class]};
 }

- (void)readHiSolarDefult:(NSDictionary *)dic
{
    [self.rows enumerateObjectsUsingBlock:^(RHVppSetCommonModel * _Nonnull rowModel, NSUInteger row_idx, BOOL * _Nonnull stop) {
       
        //充放电时间设置
        if ([rowModel.type isEqualToString:@"time"]) {
            [rowModel.items enumerateObjectsUsingBlock:^(RHVppSetCommonModel * _Nonnull itemModel, NSUInteger item_idx, BOOL * _Nonnull stop) {
                NSLog(@"key:%@   value:%@",itemModel.key,dic[itemModel.key]);
               
                //充放电使能
                if ([itemModel.type isEqualToString:@"select"]) {
                    //策略配置里是读取的strategy参数配置,不是读取设备上传的,这里有对之前 组合的使能参数分解到对应的每一个使能上
                    if (dic[@"Inv5_VM"]) {
                        NSInteger value = ([dic[@"Inv5_VM"] integerValue] &(1<<row_idx))>>row_idx;
                        //下标值
                        for (DevSettingOptionModel *select_model in itemModel.selectList) {
                            if(value == select_model.textValue){
                                itemModel.enumText = select_model.text;
                                itemModel.content = [NSString stringWithFormat:@"%ld",select_model.textValue];
                            }
                        }
                    }else{
                        //下标值
                        for (DevSettingOptionModel *select_model in itemModel.selectList) {
                            if([dic[itemModel.key] integerValue] == select_model.textValue){
                                itemModel.enumText = select_model.text;
                                itemModel.content = [NSString stringWithFormat:@"%ld",select_model.textValue];
                            }
                        }
                    }
                    
                }
                //充放电开始时间和结束时间
                if ([itemModel.type isEqualToString:@"date"]) {
                    //小时
                    NSInteger hour = [dic[itemModel.key] integerValue]/100;
                    //分钟
                    NSInteger minute = [dic[itemModel.key] integerValue]%100;
                    itemModel.content = [NSString stringWithFormat:@"%02ld:%02ld",hour,minute];//
                  
                }
                if ([itemModel.type isEqualToString:@"switch"]){
                    itemModel.content = ValidNullData(dic[itemModel.key]);
                }
                if ([itemModel.type isEqualToString:@"number"]){
                    itemModel.content = ValidNullDataToString(dic[itemModel.key],@"0");
                }
               
               
            }];
            return;
        }
        
        
        
        //开关和数值输入
        NSLog(@"key:%@   value:%@",rowModel.key,dic[rowModel.key]);
        rowModel.content = ValidNullData(dic[rowModel.key]);
        
        //选择
        if ([rowModel.type isEqualToString:@"select"]) {
            //下标值
            for (DevSettingOptionModel *select_model in rowModel.selectList) {
                if([dic[rowModel.key] integerValue] == select_model.textValue){
                    rowModel.enumText = select_model.text;
                }
            }
        }
    }];
}
@end
